using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

namespace WpfApp3.Controls;

public class ContextMenuToggleButton : ToggleButton
{
    public ContextMenu Menu { get; set; }

    protected override void OnClick()
    {
        base.OnClick();
        if (Menu != null)
        {
            if (IsChecked == true)
            {
                Menu.PlacementTarget = this;
                Menu.IsOpen = true;
            }
            else
            {
                Menu.IsOpen = false;
            }
        }
    }

    public void Show(bool show)
    {
        Visibility = show ? Visibility.Visible : Visibility.Collapsed;
    }
}
